package com.xszx.knowledge.config;

import com.xszx.knowledge.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

@Configuration
public class SpringMvcConfig implements WebMvcConfigurer {

    @Resource
    LoginInterceptor loginInterceptor;

    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/**")//表示拦截所有
                .excludePathPatterns(//放行指定的接口
                        "/doc.html", //不需要拦截的地
                        "/swagger-resources/**",
                        "/webjars/**",
                        "/v2/**",
                        "/favicon.ico",
                        "/swagger-ui.html/**",
                        "/content/getContentById",
                        "/doc/vote/**",
                        "/user/login",
                        "/user/logout/**",
                        "/category/getAll",
                        "/ebook/getAll",
                        "/doc/getAll",
                        "/doc/getContentById/**",
                        "/ebook-snapshot/getTopStatistic",
                        "/ebook-snapshot/getThirtyStatistic"
                );
    }
}
